<?php 
/**************************************************/
## Class Name - Model_City (Contains all the functions related City modules)
## Created By - Techmodi (22/08/2011)
/**************************************************/
class Model_City extends Database
{	
	function Model_City() {	
		$this->City = CITY;		
		$this->state = STATE;
		$this->country = COUNTRY;		

		$this->Database();
	}
	
	// for add City
	function addCity($array) {
		$this->InsertData($this->City, $array);
	}
	
	## List all City
	function getAllCity($search, $search_bycountry,$search_bystate,$col1='',$col2='',$col3='', $limit='', $offset='') {
		$fields = array("c.*, s.state_name, con.country_name");
		$tables = array($this->City." AS c", $this->state." AS s",  $this->country." AS con");
		$where = array("c.state_id=s.state_id AND c.country_id=con.country_id");
		
		if($search!='' && $search!='City') {	
			$where[]= "c.city_name LIKE '%".$search."%'";
		} 
		if($search_bycountry != '') {
			$where[] = "c.country_id = $search_bycountry";
		}
		if($search_bystate != '') {
			$where[] = "c.state_id = $search_bystate";
		}
		if($col1 =='0')
		{
			$order = array("city_name ASC");
		}
		if($col2 =='0')
		{
			$order = array("state_name ASC");
		}
		if($col3=='0')
		{
			$order = array("country_name ASC");
		}
		if($col1 =='1')
		{
			$order = array("city_name DESC");
		}
		if($col2 =='1')
		{
			$order = array("state_name DESC");
		}
		if($col3=='1')
		{
			$order = array("country_name DESC");
		}
		$result1 = $this->SelectData($fields,$tables, $where, $order , $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get faq details by Cityid
	function getCityDetailsById($Cityid) {
		$fields = array();	
		$tables = array($this->City);
		$result1 = $this->SelectData($fields,$tables, $where= array("city_id='".$Cityid."'"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## Edit City by Cityid
	function editCityById($array, $Cityid){
		$this->UpdateData($this->City,$array,"city_id",$Cityid,0);
	}
	
	## Update City status with multiple Cityids
	function updateCityStatus($Cityid, $status) {		
		$sql = "UPDATE ".$this->City." SET city_status='".$status."' WHERE city_id = (".$Cityid.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	## Delete City cat by id
	function deleteCityById($Cityid){
		$this->DeleteData($this->City,"city_id",$Cityid);
	}
	
	/****************************************************/
	## Update City status with multiple Cityids
	function updateMultipleCityStatus($Cityids, $status) {
		$sql = "UPDATE ".$this->City." SET city_status='".$status."' WHERE city_id IN (".$Cityids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete City category with multiple Cityids
	function deleteMultipleCity($Cityids) {
		$sql = "DELETE FROM ".$this->City." WHERE city_id IN (".$Cityids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## checking city name exit or not written by sandeep shirsat 23 aug 2011
	function checkCityName($cityname, $id='') {
		$fields = array();	
		$tables = array($this->City);
		$where= array("city_name='".$cityname."'");
		
		if($id != '') {
			$where[] = " city_id!=".$id;	
		}
		
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## List all active city name
	function getAllCityWithActiveStatus() {
		$fields = array('');	
		$tables = array($this->City);
		$where= array("city_status='1'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get city details by stateid
	function getAllCityDetailsByStateId($state_id) {
		$fields = array();	
		$tables = array($this->City);
		$result1 = $this->SelectData($fields,$tables, $where= array("state_id='".$state_id."'"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get city details by stateid
	function getAllCityDetailsByStateIdWithActiveStattus($state_id) {
		$fields = array();	
		$tables = array($this->City);
		$result1 = $this->SelectData($fields,$tables, $where= array("postalcode='".$state_id."' and city_status='1'"), $order = array("city_name ASC"), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	## Get city details by stateid
	function getAllPostalCodeDetailsByStateIdWithActiveStattus($state_id) {
		$fields = array(' Distinct postalcode ');	
		$tables = array($this->City);
		$result1 = $this->SelectData($fields,$tables, $where= array("state_id='".$state_id."' and city_status='1'"), $order = array("postalcode ASC"), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
}
?>


